package com.lwh.springboot.service.impl;
import com.lwh.springboot.mapper.CarTypeMapper;
import com.lwh.springboot.pojo.entity.CarType;
import com.lwh.springboot.pojo.vo.CarTypeCountVO;
import com.lwh.springboot.service.ICarTypeService;
import com.lwh.springboot.util.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CarTypeServiceImpl implements ICarTypeService {

    @Autowired
    private CarTypeMapper carTypeMapper;

    //业务
    @Override
    public List<CarType> selectAll() {
        List<CarType> list = carTypeMapper.selectAll();
        return list;
    }

    @Override
    public void deleteById(Integer id) {
        carTypeMapper.deleteById(id);
    }

    @Override
    public void add(CarType carTypeType) {
        carTypeMapper.add(carTypeType);
    }

    @Override
    public CarType selectById(Integer id) {
        return carTypeMapper.selectById(id);
    }

    @Override
    public void update(CarType carTypeType) {
        carTypeMapper.update(carTypeType);
    }

    // totalCount:101
    // pageSize:10
    @Override
    public PageInfo selectByPage(Integer pageNo, Integer pageSize) {
        // limit
        int offset = (pageNo - 1) * pageSize;
        //查找当前也数据
        List<CarType> list = carTypeMapper.selectByPage(offset, pageSize);
        //查找总的数量，目的是为了算总的页数totalPage
        int totalCount = carTypeMapper.selectTotalCount();
        int totalPage = (int)Math.ceil((double) totalCount / pageSize);

        return new PageInfo<CarType>(list, totalPage, pageNo, pageSize);
    }

    @Override
    public void deleteAll(Integer[] ids) {
        carTypeMapper.deleteAll(ids);
    }

    @Override
    public List<CarTypeCountVO> selectCarTypeCount() {
        return carTypeMapper.selectCarTypeCount();
    }
}
